import java.util.HashSet;
import java.util.Random;


public abstract class Function {

	double normInf;
	
	public Function(double norm) {
		this.normInf = norm;
	}
	
	abstract Complex getVal(int i);
	
	public double getNorm(int norm, int size) {
		int samp = Math.min(size, 10);
		double answer = 0;
		HashSet<Integer> var = genRandSet(samp, size);
		for (int i: var) {
			Complex val = this.getVal(i);
			double valNorm = Complex.norm2(val);
			answer += valNorm;
			}
		return Math.sqrt(answer); 
	}
	
	public double getNormInfinity() {
		return this.normInf;
}


	public static HashSet<Integer> genRandSet(int num, int size){
		HashSet<Integer> answer = new HashSet<Integer>();
		if (num == size) {
			for (int j=0; j<num; j++) {
				answer.add(j);
			}
			return answer;
		}
		Random rand=new Random();
		for(int i = 0; i<num; i++) {
			int elem = rand.nextInt(size);
			if(answer.contains(elem)) {
				i--;
			}
			else{
				answer.add(elem);
			}
		}
		return answer;
	}
}